﻿using Dapper;
using BgWorks.Common;
using BgWorks.Models;
using BgWorks.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BgWorks.Works
{
    public class SqlWork:IWork
    {       
        public void WorkThing(JobModel jobModel)
        {
            JobData model =jobModel.Data;
            if (model.SqlType == "oracle")
            {
                var conn = string.IsNullOrEmpty(model.Connectionkey) ? DapperFactory.CreateOracleConnect(model.ConnectionString) : DapperFactory.CreateOracleConnection(model.Connectionkey);
                try
                {
                    using (conn)
                    {
                        conn.Execute(model.Sql, null);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.GetLog().Error("oracle执行sql异常:" + ex);
                    throw new Exception("oracle执行sql异常:" + ex);
                }
            }
        }
    }
}
